//
//  FANEmoticonButton.swift
//  Weibo - Swift
//
//  Created by user on 16/4/28.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit

class FANEmoticonButton: UIButton {

    var emoticon:FANEmoticon?{
        
        didSet{
            
                guard let _ = emoticon else{
                    
                    return
                }
            
                //emoji
                if emoticon!.type == "1"{
                    
                self.setTitle((emoticon!.code! as NSString).emoji(), forState: UIControlState.Normal)
                    
                self.setImage(nil, forState: UIControlState.Normal)
                    
                self.titleLabel?.font = UIFont.systemFontOfSize(33)
                    
                }else{//defaults,lxh
                    
                 let image = UIImage(named:"\(emoticon!.folderName ?? "")/\(emoticon!.png!)" , inBundle: FANEmoticonViewModel.sharedEmoticon.emoticonBundle, compatibleWithTraitCollection: nil)
                    
                 self.setTitle("", forState: UIControlState.Normal)
                    
                 self.setImage(image, forState: UIControlState.Normal)
                    
                }
            
        }
    }
}
